package xyz.ddlnt.user.mq.publisher;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ZZULI_SE 210910
 * @data 2025/4/25 18:37
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/mq/mq")
public class MqPublisher {

    private final RabbitTemplate rabbitTemplate;

    @GetMapping("/send")
    public void send() {
        try {
            rabbitTemplate.convertAndSend("usr.direct", "usr.testKey", "消息发送成功");
            log.info("消息发送成功");
        }catch (Exception e) {
            log.error("消息发送异常:{}", e.getMessage());
        }
    }
}
